package common

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type ApiResult struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func HttpResponse(c *gin.Context, code int, message string, data interface{}) {
	c.JSON(http.StatusOK, ApiResult{code, message, data})
}

func Ok(c *gin.Context) {
	HttpResponse(c, 200, "成功", nil)
}

func OkWithMsg(c *gin.Context, message string) {
	HttpResponse(c, 200, message, nil)
}

func OkWithData(c *gin.Context, data interface{}) {
	HttpResponse(c, 200, "成功", data)
}

func Fail(c *gin.Context) {
	HttpResponse(c, 400, "失败", nil)
}

func FailWithMsg(c *gin.Context, message string) {
	HttpResponse(c, 400, message, nil)
}

func FailWithDetail(c *gin.Context, message string, data interface{}) {
	HttpResponse(c, 400, message, data)
}
